using CfgTable;
using IQIGame.Onigao.Framework;
using NetProtocol.POD;

namespace IQIGame.Onigao.GamePlay
{
    public class LevelBuffData : IReusableClass
    {
        /*-- members --*/
        /// <summary>
        /// 
        /// </summary>
        public int cid => cfgBuff.Id;

        /// <summary>
        /// 
        /// </summary>
        public int stack { protected set; get; }

        /// <summary>
        /// buff终止时间
        /// </summary>
        public long endTime { protected set; get; }

        public CfgLevelBuff cfgBuff { protected set; get; }

        public uint MaxStore => 20;

        public static LevelBuffData CreateLevelBuff(LevelBuffPOD buffPod)
        {
            LevelBuffData buffData = ClassPool.Get<LevelBuffData>();
            buffData.cfgBuff = TableCenter.levelBuff.Get(buffPod.cid);
            buffData.stack = buffPod.stack;
            buffData.endTime = GameServerModule.Instance.ServerTimestamp + (int)buffPod.leftSec;
            return buffData;
        }

        /// <summary>
        /// 通过pod刷新，一般是层数或者时间
        /// </summary>
        /// <param name="buffPod"></param>
        public void RefreshByPod(LevelBuffPOD buffPod)
        {
            stack = buffPod.stack;
            endTime = GameServerModule.Instance.ServerTimestamp + (int)buffPod.leftSec;
        }

        public void OnReset()
        {
            stack = 0;
            endTime = 0;
            cfgBuff = null;
        }
    }
}
